home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / MPW / flex 2.4.6 / flexdef.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-21  |  30.6 KB  |  913 lines  |  [TEXT/MPS ]

  1. /* flexdef - definitions file for flex */
  2.  
  3. /*-
  4.  * Copyright (c) 1990 The Regents of the University of California.
  5.  * All rights reserved.
  6.  *
  7.  * This code is derived from software contributed to Berkeley by
  8.  * Vern Paxson.
  9.  * 
  10.  * The United States Government has rights in this work pursuant
  11.  * to contract no. DE-AC03-76SF00098 between the United States
  12.  * Department of Energy and the University of California.
  13.  *
  14.  * Redistribution and use in source and binary forms are permitted provided
  15.  * that: (1) source distributions retain this entire copyright notice and
  16.  * comment, and (2) distributions including binaries display the following
  17.  * acknowledgement:  ``This product includes software developed by the
  18.  * University of California, Berkeley and its contributors'' in the
  19.  * documentation or other materials provided with the distribution and in
  20.  * all advertising materials mentioning features or use of this software.
  21.  * Neither the name of the University nor the names of its contributors may
  22.  * be used to endorse or promote products derived from this software without
  23.  * specific prior written permission.
  24.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  25.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  26.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27.  */
  28.  
  29. /* @(#) $Header: flexdef.h,v 1.2 94/01/04 14:33:14 vern Exp $ (LBL) */
  30.  
  31. #include <stdio.h>
  32. #include <ctype.h>
  33.  
  34. #if HAVE_STRING_H
  35. #include <string.h>
  36. #else
  37. #include <strings.h>
  38. #endif
  39.  
  40. #if __STDC__
  41. #include <stdlib.h>
  42. #endif
  43.  
  44. /* Always be prepared to generate an 8-bit scanner. */
  45. #define CSIZE 256
  46. #define Char unsigned char
  47.  
  48. /* Size of input alphabet - should be size of ASCII set. */
  49. #ifndef DEFAULT_CSIZE
  50. #define DEFAULT_CSIZE 128
  51. #endif
  52.  
  53. #ifndef PROTO
  54. #ifdef __STDC__
  55. #define PROTO(proto) proto
  56. #else
  57. #define PROTO(proto) ()
  58. #endif
  59. #endif
  60.  
  61. #ifdef VMS
  62. #define unlink delete
  63. #define SHORT_FILE_NAMES
  64. #endif
  65.  
  66. #ifdef MS_DOS
  67. #define SHORT_FILE_NAMES
  68. #endif
  69.  
  70. #ifdef macintosh
  71. #define unlink remove
  72. # ifdef MPW
  73. #  include <CursorCtl.h>
  74. # endif
  75. #endif
  76.  
  77. /* Maximum line length we'll have to deal with. */
  78. #define MAXLINE 2048
  79.  
  80. #ifndef MIN
  81. #define MIN(x,y) ((x) < (y) ? (x) : (y))
  82. #endif
  83. #ifndef MAX
  84. #define MAX(x,y) ((x) > (y) ? (x) : (y))
  85. #endif
  86. #ifndef ABS
  87. #define ABS(x) ((x) < 0 ? -(x) : (x))
  88. #endif
  89.  
  90.  
  91. /* ANSI C does not guarantee that isascii() is defined */
  92. #ifndef isascii
  93. #ifdef MPW    /* Lifted from Apple's <ctype.h> */
  94. #define isascii(c)        ((unsigned char)(c)<=0177)
  95. #else
  96. #define isascii(c) ((c) <= 0177)
  97. #endif
  98. #endif
  99.  
  100.  
  101. #define true 1
  102. #define false 0
  103.  
  104.  
  105. /* Special chk[] values marking the slots taking by end-of-buffer and action
  106.  * numbers.
  107.  */
  108. #define EOB_POSITION -1
  109. #define ACTION_POSITION -2
  110.  
  111. /* Number of data items per line for -f output. */
  112. #define NUMDATAITEMS 10
  113.  
  114. /* Number of lines of data in -f output before inserting a blank line for
  115.  * readability.
  116.  */
  117. #define NUMDATALINES 10
  118.  
  119. /* Transition_struct_out() definitions. */
  120. #define TRANS_STRUCT_PRINT_LENGTH 15
  121.  
  122. /* Returns true if an nfa state has an epsilon out-transition slot
  123.  * that can be used.  This definition is currently not used.
  124.  */
  125. #define FREE_EPSILON(state) \
  126.     (transchar[state] == SYM_EPSILON && \
  127.      trans2[state] == NO_TRANSITION && \
  128.      finalst[state] != state)
  129.  
  130. /* Returns true if an nfa state has an epsilon out-transition character
  131.  * and both slots are free
  132.  */
  133. #define SUPER_FREE_EPSILON(state) \
  134.     (transchar[state] == SYM_EPSILON && \
  135.      trans1[state] == NO_TRANSITION) \
  136.  
  137. /* Maximum number of NFA states that can comprise a DFA state.  It's real
  138.  * big because if there's a lot of rules, the initial state will have a
  139.  * huge epsilon closure.
  140.  */
  141. #define INITIAL_MAX_DFA_SIZE 750
  142. #define MAX_DFA_SIZE_INCREMENT 750
  143.  
  144.  
  145. /* A note on the following masks.  They are used to mark accepting numbers
  146.  * as being special.  As such, they implicitly limit the number of accepting
  147.  * numbers (i.e., rules) because if there are too many rules the rule numbers
  148.  * will overload the mask bits.  Fortunately, this limit is \large/ (0x2000 ==
  149.  * 8192) so unlikely to actually cause any problems.  A check is made in
  150.  * new_rule() to ensure that this limit is not reached.
  151.  */
  152.  
  153. /* Mask to mark a trailing context accepting number. */
  154. #define YY_TRAILING_MASK 0x2000
  155.  
  156. /* Mask to mark the accepting number of the "head" of a trailing context
  157.  * rule.
  158.  */
  159. #define YY_TRAILING_HEAD_MASK 0x4000
  160.  
  161. /* Maximum number of rules, as outlined in the above note. */
  162. #define MAX_RULE (YY_TRAILING_MASK - 1)
  163.  
  164.  
  165. /* NIL must be 0.  If not, its special meaning when making equivalence classes
  166.  * (it marks the representative of a given e.c.) will be unidentifiable.
  167.  */
  168. #define NIL 0
  169.  
  170. #define JAM -1    /* to mark a missing DFA transition */
  171. #define NO_TRANSITION NIL
  172. #define UNIQUE -1    /* marks a symbol as an e.c. representative */
  173. #define INFINITY -1    /* for x{5,} constructions */
  174.  
  175. #define INITIAL_MAX_CCLS 100    /* max number of unique character classes */
  176. #define MAX_CCLS_INCREMENT 100
  177.  
  178. /* Size of table holding members of character classes. */
  179. #define INITIAL_MAX_CCL_TBL_SIZE 500
  180. #define MAX_CCL_TBL_SIZE_INCREMENT 250
  181.  
  182. #define INITIAL_MAX_RULES 100    /* default maximum number of rules */
  183. #define MAX_RULES_INCREMENT 100
  184.  
  185. #define INITIAL_MNS 2000    /* default maximum number of nfa states */
  186. #define MNS_INCREMENT 1000    /* amount to bump above by if it's not enough */
  187.  
  188. #define INITIAL_MAX_DFAS 1000    /* default maximum number of dfa states */
  189. #define MAX_DFAS_INCREMENT 1000
  190.  
  191. #define JAMSTATE -32766    /* marks a reference to the state that always jams */
  192.  
  193. /* Enough so that if it's subtracted from an NFA state number, the result
  194.  * is guaranteed to be negative.
  195.  */
  196. #define MARKER_DIFFERENCE 32000
  197. #define MAXIMUM_MNS 31999
  198.  
  199. /* Maximum number of nxt/chk pairs for non-templates. */
  200. #define INITIAL_MAX_XPAIRS 2000
  201. #define MAX_XPAIRS_INCREMENT 2000
  202.  
  203. /* Maximum number of nxt/chk pairs needed for templates. */
  204. #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
  205. #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
  206.  
  207. #define SYM_EPSILON (CSIZE + 1)    /* to mark transitions on the symbol epsilon */
  208.  
  209. #define INITIAL_MAX_SCS 40    /* maximum number of start conditions */
  210. #define MAX_SCS_INCREMENT 40    /* amount to bump by if it's not enough */
  211.  
  212. #define ONE_STACK_SIZE 500    /* stack of states with only one out-transition */
  213. #define SAME_TRANS -1    /* transition is the same as "default" entry for state */
  214.  
  215. /* The following percentages are used to tune table compression:
  216.  
  217.  * The percentage the number of out-transitions a state must be of the
  218.  * number of equivalence classes in order to be considered for table
  219.  * compaction by using protos.
  220.  */
  221. #define PROTO_SIZE_PERCENTAGE 15
  222.  
  223. /* The percentage the number of homogeneous out-transitions of a state
  224.  * must be of the number of total out-transitions of the state in order
  225.  * that the state's transition table is first compared with a potential 
  226.  * template of the most common out-transition instead of with the first
  227.  * proto in the proto queue.
  228.  */
  229. #define CHECK_COM_PERCENTAGE 50
  230.  
  231. /* The percentage the number of differences between a state's transition
  232.  * table and the proto it was first compared with must be of the total
  233.  * number of out-transitions of the state in order to keep the first
  234.  * proto as a good match and not search any further.
  235.  */
  236. #define FIRST_MATCH_DIFF_PERCENTAGE 10
  237.  
  238. /* The percentage the number of differences between a state's transition
  239.  * table and the most similar proto must be of the state's total number
  240.  * of out-transitions to use the proto as an acceptable close match.
  241.  */
  242. #define ACCEPTABLE_DIFF_PERCENTAGE 50
  243.  
  244. /* The percentage the number of homogeneous out-transitions of a state
  245.  * must be of the number of total out-transitions of the state in order
  246.  * to consider making a template from the state.
  247.  */
  248. #define TEMPLATE_SAME_PERCENTAGE 60
  249.  
  250. /* The percentage the number of differences between a state's transition
  251.  * table and the most similar proto must be of the state's total number
  252.  * of out-transitions to create a new proto from the state.
  253.  */
  254. #define NEW_PROTO_DIFF_PERCENTAGE 20
  255.  
  256. /* The percentage the total number of out-transitions of a state must be
  257.  * of the number of equivalence classes in order to consider trying to
  258.  * fit the transition table into "holes" inside the nxt/chk table.
  259.  */
  260. #define INTERIOR_FIT_PERCENTAGE 15
  261.  
  262. /* Size of region set aside to cache the complete transition table of
  263.  * protos on the proto queue to enable quick comparisons.
  264.  */
  265. #define PROT_SAVE_SIZE 2000
  266.  
  267. #define MSP 50    /* maximum number of saved protos (protos on the proto queue) */
  268.  
  269. /* Maximum number of out-transitions a state can have that we'll rummage
  270.  * around through the interior of the internal fast table looking for a
  271.  * spot for it.
  272.  */
  273. #define MAX_XTIONS_FULL_INTERIOR_FIT 4
  274.  
  275. /* Maximum number of rules which will be reported as being associated
  276.  * with a DFA state.
  277.  */
  278. #define MAX_ASSOC_RULES 100
  279.  
  280. /* Number that, if used to subscript an array, has a good chance of producing
  281.  * an error; should be small enough to fit into a short.
  282.  */
  283. #define BAD_SUBSCRIPT -32767
  284.  
  285. /* Absolute value of largest number that can be stored in a short, with a
  286.  * bit of slop thrown in for general paranoia.
  287.  */
  288. #define MAX_SHORT 32700
  289.  
  290.  
  291. /* Declarations for global variables. */
  292.  
  293. /* Variables for symbol tables:
  294.  * sctbl - start-condition symbol table
  295.  * ndtbl - name-definition symbol table
  296.  * ccltab - character class text symbol table
  297.  */
  298.  
  299. struct hash_entry
  300.     {
  301.     struct hash_entry *prev, *next;
  302.     char *name;
  303.     char *str_val;
  304.     int int_val;
  305.     } ;
  306.  
  307. typedef struct hash_entry **hash_table;
  308.  
  309. #define NAME_TABLE_HASH_SIZE 101
  310. #define START_COND_HASH_SIZE 101
  311. #define CCL_HASH_SIZE 101
  312.  
  313. extern struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE]; 
  314. extern struct hash_entry *sctbl[START_COND_HASH_SIZE];
  315. extern struct hash_entry *ccltab[CCL_HASH_SIZE];
  316.  
  317.  
  318. /* Variables for flags:
  319.  * printstats - if true (-v), dump statistics
  320.  * syntaxerror - true if a syntax error has been found
  321.  * eofseen - true if we've seen an eof in the input file
  322.  * ddebug - if true (-d), make a "debug" scanner
  323.  * trace - if true (-T), trace processing
  324.  * nowarn - if true (-w), do not generate warnings
  325.  * spprdflt - if true (-s), suppress the default rule
  326.  * interactive - if true (-I), generate an interactive scanner
  327.  * caseins - if true (-i), generate a case-insensitive scanner
  328.  * lex_compat - if true (-l), maximize compatibility with AT&T lex
  329.  * useecs - if true (-Ce flag), use equivalence classes
  330.  * fulltbl - if true (-Cf flag), don't compress the DFA state table
  331.  * usemecs - if true (-Cm flag), use meta-equivalence classes
  332.  * fullspd - if true (-F flag), use Jacobson method of table representation
  333.  * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
  334.  * performance_report - if > 0 (i.e., -p flag), generate a report relating
  335.  *   to scanner performance; if > 1 (-p -p), report on minor performance
  336.  *   problems, too
  337.  * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file
  338.  *   listing backing-up states
  339.  * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class;
  340.  *   otherwise, a standard C scanner
  341.  * long_align - if true (-Ca flag), favor long-word alignment.
  342.  * use_read - if true (-f, -F, or -Cr) then use read() for scanner input;
  343.  *   otherwise, use fread().
  344.  * yytext_is_array - if true (i.e., %array directive), then declare
  345.  *   yytext as a array instead of a character pointer.  Nice and inefficient.
  346.  * csize - size of character set for the scanner we're generating;
  347.  *   128 for 7-bit chars and 256 for 8-bit
  348.  * yymore_used - if true, yymore() is used in input rules
  349.  * reject - if true, generate back-up tables for REJECT macro
  350.  * real_reject - if true, scanner really uses REJECT (as opposed to just
  351.  *   having "reject" set for variable trailing context)
  352.  * continued_action - true if this rule's action is to "fall through" to
  353.  *   the next rule's action (i.e., the '|' action)
  354.  * yymore_really_used - has a REALLY_xxx value indicating whether a
  355.  *   %used or %notused was used with yymore()
  356.  * reject_really_used - same for REJECT
  357.  */
  358.  
  359. extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
  360. extern int interactive, caseins, lex_compat, useecs, fulltbl, usemecs;
  361. extern int fullspd, gen_line_dirs, performance_report, backing_up_report;
  362. extern int C_plus_plus, long_align, use_read, yytext_is_array, csize;
  363. extern int yymore_used, reject, real_reject, continued_action;
  364.  
  365. #define REALLY_NOT_DETERMINED 0
  366. #define REALLY_USED 1
  367. #define REALLY_NOT_USED 2
  368. extern int yymore_really_used, reject_really_used;
  369.  
  370.  
  371. /* Variables used in the flex input routines:
  372.  * datapos - characters on current output line
  373.  * dataline - number of contiguous lines of data in current data
  374.  *     statement.  Used to generate readable -f output
  375.  * linenum - current input line number
  376.  * skelfile - the skeleton file
  377.  * skel - compiled-in skeleton array
  378.  * skel_ind - index into "skel" array, if skelfile is nil
  379.  * yyin - input file
  380.  * backing_up_file - file to summarize backing-up states to
  381.  * infilename - name of input file
  382.  * input_files - array holding names of input files
  383.  * num_input_files - size of input_files array
  384.  * program_name - name with which program was invoked 
  385.  *
  386.  * action_array - array to hold the rule actions
  387.  * action_size - size of action_array
  388.  * defs1_offset - index where the user's section 1 definitions start
  389.  *    in action_array
  390.  * prolog_offset - index where the prolog starts in action_array
  391.  * action_offset - index where the non-prolog starts in action_array
  392.  * action_index - index where the next action should go, with respect
  393.  *     to "action_array"
  394.  */
  395.  
  396. extern int datapos, dataline, linenum;
  397. extern FILE *skelfile, *yyin, *backing_up_file;
  398. extern char *skel[];
  399. extern int skel_ind;
  400. extern char *infilename;
  401. extern char **input_files;
  402. extern int num_input_files;
  403. extern char *program_name;
  404.  
  405. extern char *action_array;
  406. extern int action_size;
  407. extern int defs1_offset, prolog_offset, action_offset, action_index;
  408.  
  409.  
  410. /* Variables for stack of states having only one out-transition:
  411.  * onestate - state number
  412.  * onesym - transition symbol
  413.  * onenext - target state
  414.  * onedef - default base entry
  415.  * onesp - stack pointer
  416.  */
  417.  
  418. extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
  419. extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
  420.  
  421.  
  422. /* Variables for nfa machine data:
  423.  * current_mns - current maximum on number of NFA states
  424.  * num_rules - number of the last accepting state; also is number of
  425.  *     rules created so far
  426.  * num_eof_rules - number of <<EOF>> rules
  427.  * default_rule - number of the default rule
  428.  * current_max_rules - current maximum number of rules
  429.  * lastnfa - last nfa state number created
  430.  * firstst - physically the first state of a fragment
  431.  * lastst - last physical state of fragment
  432.  * finalst - last logical state of fragment
  433.  * transchar - transition character
  434.  * trans1 - transition state
  435.  * trans2 - 2nd transition state for epsilons
  436.  * accptnum - accepting number
  437.  * assoc_rule - rule associated with this NFA state (or 0 if none)
  438.  * state_type - a STATE_xxx type identifying whether the state is part
  439.  *     of a normal rule, the leading state in a trailing context
  440.  *     rule (i.e., the state which marks the transition from
  441.  *     recognizing the text-to-be-matched to the beginning of
  442.  *     the trailing context), or a subsequent state in a trailing
  443.  *     context rule
  444.  * rule_type - a RULE_xxx type identifying whether this a ho-hum
  445.  *     normal rule or one which has variable head & trailing
  446.  *     context
  447.  * rule_linenum - line number associated with rule
  448.  * rule_useful - true if we've determined that the rule can be matched
  449.  */
  450.  
  451. extern int current_mns, num_rules, num_eof_rules, default_rule;
  452. extern int current_max_rules, lastnfa;
  453. extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
  454. extern int *accptnum, *assoc_rule, *state_type;
  455. extern int *rule_type, *rule_linenum, *rule_useful;
  456.  
  457. /* Different types of states; values are useful as masks, as well, for
  458.  * routines like check_trailing_context().
  459.  */
  460. #define STATE_NORMAL 0x1
  461. #define STATE_TRAILING_CONTEXT 0x2
  462.  
  463. /* Global holding current type of state we're making. */
  464.  
  465. extern int current_state_type;
  466.  
  467. /* Different types of rules. */
  468. #define RULE_NORMAL 0
  469. #define RULE_VARIABLE 1
  470.  
  471. /* True if the input rules include a rule with both variable-length head
  472.  * and trailing context, false otherwise.
  473.  */
  474. extern int variable_trailing_context_rules;
  475.  
  476.  
  477. /* Variables for protos:
  478.  * numtemps - number of templates created
  479.  * numprots - number of protos created
  480.  * protprev - backlink to a more-recently used proto
  481.  * protnext - forward link to a less-recently used proto
  482.  * prottbl - base/def table entry for proto
  483.  * protcomst - common state of proto
  484.  * firstprot - number of the most recently used proto
  485.  * lastprot - number of the least recently used proto
  486.  * protsave contains the entire state array for protos
  487.  */
  488.  
  489. extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
  490. extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
  491.  
  492.  
  493. /* Variables for managing equivalence classes:
  494.  * numecs - number of equivalence classes
  495.  * nextecm - forward link of Equivalence Class members
  496.  * ecgroup - class number or backward link of EC members
  497.  * nummecs - number of meta-equivalence classes (used to compress
  498.  *   templates)
  499.  * tecfwd - forward link of meta-equivalence classes members
  500.  * tecbck - backward link of MEC's
  501.  */
  502.  
  503. /* Reserve enough room in the equivalence class arrays so that we
  504.  * can use the CSIZE'th element to hold equivalence class information
  505.  * for the NUL character.  Later we'll move this information into
  506.  * the 0th element.
  507.  */
  508. extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
  509.  
  510. /* Meta-equivalence classes are indexed starting at 1, so it's possible
  511.  * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
  512.  * slots total (since the arrays are 0-based).  nextecm[] and ecgroup[]
  513.  * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
  514.  */
  515. extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
  516.  
  517.  
  518. /* Variables for start conditions:
  519.  * lastsc - last start condition created
  520.  * current_max_scs - current limit on number of start conditions
  521.  * scset - set of rules active in start condition
  522.  * scbol - set of rules active only at the beginning of line in a s.c.
  523.  * scxclu - true if start condition is exclusive
  524.  * sceof - true if start condition has EOF rule
  525.  * scname - start condition name
  526.  * actvsc - stack of active start conditions for the current rule;
  527.  *     a negative entry means that the start condition is *not*
  528.  *    active for the current rule.  Start conditions may appear
  529.  *    multiple times on the stack; the entry for it closest
  530.  *    to the top of the stack (i.e., actvsc[actvp]) is the
  531.  *    one to use.  Others are present from "<sc>{" scoping
  532.  *    constructs.
  533.  */
  534.  
  535. extern int lastsc, current_max_scs, *scset, *scbol, *scxclu, *sceof, *actvsc;
  536. extern char **scname;
  537.  
  538.  
  539. /* Variables for dfa machine data:
  540.  * current_max_dfa_size - current maximum number of NFA states in DFA
  541.  * current_max_xpairs - current maximum number of non-template xtion pairs
  542.  * current_max_template_xpairs - current maximum number of template pairs
  543.  * current_max_dfas - current maximum number DFA states
  544.  * lastdfa - last dfa state number created
  545.  * nxt - state to enter upon reading character
  546.  * chk - check value to see if "nxt" applies
  547.  * tnxt - internal nxt table for templates
  548.  * base - offset into "nxt" for given state
  549.  * def - where to go if "chk" disallows "nxt" entry
  550.  * nultrans - NUL transition for each state
  551.  * NUL_ec - equivalence class of the NUL character
  552.  * tblend - last "nxt/chk" table entry being used
  553.  * firstfree - first empty entry in "nxt/chk" table
  554.  * dss - nfa state set for each dfa
  555.  * dfasiz - size of nfa state set for each dfa
  556.  * dfaacc - accepting set for each dfa state (if using REJECT), or accepting
  557.  *    number, if not
  558.  * accsiz - size of accepting set for each dfa state
  559.  * dhash - dfa state hash value
  560.  * numas - number of DFA accepting states created; note that this
  561.  *    is not necessarily the same value as num_rules, which is the analogous
  562.  *    value for the NFA
  563.  * numsnpairs - number of state/nextstate transition pairs
  564.  * jambase - position in base/def where the default jam table starts
  565.  * jamstate - state number corresponding to "jam" state
  566.  * end_of_buffer_state - end-of-buffer dfa state number
  567.  */
  568.  
  569. extern int current_max_dfa_size, current_max_xpairs;
  570. extern int current_max_template_xpairs, current_max_dfas;
  571. extern int lastdfa, *nxt, *chk, *tnxt;
  572. extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
  573. extern union dfaacc_union
  574.     {
  575.     int *dfaacc_set;
  576.     int dfaacc_state;
  577.     } *dfaacc;
  578. extern int *accsiz, *dhash, numas;
  579. extern int numsnpairs, jambase, jamstate;
  580. extern int end_of_buffer_state;
  581.  
  582. /* Variables for ccl information:
  583.  * lastccl - ccl index of the last created ccl
  584.  * current_maxccls - current limit on the maximum number of unique ccl's
  585.  * cclmap - maps a ccl index to its set pointer
  586.  * ccllen - gives the length of a ccl
  587.  * cclng - true for a given ccl if the ccl is negated
  588.  * cclreuse - counts how many times a ccl is re-used
  589.  * current_max_ccl_tbl_size - current limit on number of characters needed
  590.  *    to represent the unique ccl's
  591.  * ccltbl - holds the characters in each ccl - indexed by cclmap
  592.  */
  593.  
  594. extern int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse;
  595. extern int current_max_ccl_tbl_size;
  596. extern Char *ccltbl;
  597.  
  598.  
  599. /* Variables for miscellaneous information:
  600.  * nmstr - last NAME scanned by the scanner
  601.  * sectnum - section number currently being parsed
  602.  * nummt - number of empty nxt/chk table entries
  603.  * hshcol - number of hash collisions detected by snstods
  604.  * dfaeql - number of times a newly created dfa was equal to an old one
  605.  * numeps - number of epsilon NFA states created
  606.  * eps2 - number of epsilon states which have 2 out-transitions
  607.  * num_reallocs - number of times it was necessary to realloc() a group
  608.  *      of arrays
  609.  * tmpuses - number of DFA states that chain to templates
  610.  * totnst - total number of NFA states used to make DFA states
  611.  * peakpairs - peak number of transition pairs we had to store internally
  612.  * numuniq - number of unique transitions
  613.  * numdup - number of duplicate transitions
  614.  * hshsave - number of hash collisions saved by checking number of states
  615.  * num_backing_up - number of DFA states requiring backing up
  616.  * bol_needed - whether scanner needs beginning-of-line recognition
  617.  */
  618.  
  619. extern char nmstr[MAXLINE];
  620. extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
  621. extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
  622. extern int num_backing_up, bol_needed;
  623.  
  624. void *allocate_array PROTO((int, int));
  625. void *reallocate_array PROTO((void*, int, int));
  626.  
  627. void *flex_alloc PROTO((unsigned int));
  628. void *flex_realloc PROTO((void*, unsigned int));
  629. void flex_free PROTO((void*));
  630.  
  631. #define allocate_integer_array(size) \
  632.     (int *) allocate_array( size, sizeof( int ) )
  633.  
  634. #define reallocate_integer_array(array,size) \
  635.     (int *) reallocate_array( (void *) array, size, sizeof( int ) )
  636.  
  637. #define allocate_int_ptr_array(size) \
  638.     (int **) allocate_array( size, sizeof( int * ) )
  639.  
  640. #define allocate_char_ptr_array(size) \
  641.     (char **) allocate_array( size, sizeof( char * ) )
  642.  
  643. #define allocate_dfaacc_union(size) \
  644.     (union dfaacc_union *) \
  645.         allocate_array( size, sizeof( union dfaacc_union ) )
  646.  
  647. #define reallocate_int_ptr_array(array,size) \
  648.     (int **) reallocate_array( (void *) array, size, sizeof( int * ) )
  649.  
  650. #define reallocate_char_ptr_array(array,size) \
  651.     (char **) reallocate_array( (void *) array, size, sizeof( char * ) )
  652.  
  653. #define reallocate_dfaacc_union(array, size) \
  654.     (union dfaacc_union *) \
  655.     reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) )
  656.  
  657. #define allocate_character_array(size) \
  658.     (char *) allocate_array( size, sizeof( char ) )
  659.  
  660. #define reallocate_character_array(array,size) \
  661.     (char *) reallocate_array( (void *) array, size, sizeof( char ) )
  662.  
  663. #define allocate_Character_array(size) \
  664.     (Char *) allocate_array( size, sizeof( Char ) )
  665.  
  666. #define reallocate_Character_array(array,size) \
  667.     (Char *) reallocate_array( (void *) array, size, sizeof( Char ) )
  668.  
  669.  
  670. /* Used to communicate between scanner and parser.  The type should really
  671.  * be YYSTYPE, but we can't easily get our hands on it.
  672.  */
  673. extern int yylval;
  674.  
  675.  
  676. /* External functions that are cross-referenced among the flex source files. */
  677.  
  678.  
  679. /* from file ccl.c */
  680.  
  681. extern void ccladd PROTO((int, int));    /* add a single character to a ccl */
  682. extern int cclinit PROTO((void));    /* make an empty ccl */
  683. extern void cclnegate PROTO((int));    /* negate a ccl */
  684.  
  685. /* List the members of a set of characters in CCL form. */
  686. extern void list_character_set PROTO((FILE*, int[]));
  687.  
  688.  
  689. /* from file dfa.c */
  690.  
  691. /* Increase the maximum number of dfas. */
  692. extern void increase_max_dfas PROTO((void));
  693.  
  694. extern void ntod PROTO((void));    /* convert a ndfa to a dfa */
  695.  
  696.  
  697. /* from file ecs.c */
  698.  
  699. /* Convert character classes to set of equivalence classes. */
  700. extern void ccl2ecl PROTO((void));
  701.  
  702. /* Associate equivalence class numbers with class members. */
  703. extern int cre8ecs PROTO((int[], int[], int));
  704.  
  705. /* Update equivalence classes based on character class transitions. */
  706. extern void mkeccl PROTO((Char[], int, int[], int[], int, int));
  707.  
  708. /* Create equivalence class for single character. */
  709. extern void mkechar PROTO((int, int[], int[]));
  710.  
  711.  
  712. /* from file gen.c */
  713.  
  714. extern void make_tables PROTO((void));    /* generate transition tables */
  715.  
  716.  
  717. /* from file main.c */
  718.  
  719. extern void flexend PROTO((int));
  720. extern void usage PROTO((void));
  721.  
  722.  
  723. /* from file misc.c */
  724.  
  725. /* Add the given text to the stored actions. */
  726. extern void add_action PROTO(( char *new_text ));
  727.  
  728. /* True if a string is all lower case. */
  729. extern int all_lower PROTO((register char *));
  730.  
  731. /* True if a string is all upper case. */
  732. extern int all_upper PROTO((register char *));
  733.  
  734. /* Bubble sort an integer array. */
  735. extern void bubble PROTO((int [], int));
  736.  
  737. /* Check a character to make sure it's in the expected range. */
  738. extern void check_char PROTO((int c));
  739.  
  740. /* Shell sort a character array. */
  741. extern void cshell PROTO((Char [], int, int));
  742.  
  743. /* Finish up a block of data declarations. */
  744. extern void dataend PROTO((void));
  745.  
  746. /* Report an error message and terminate. */
  747. extern void flexerror PROTO((char[]));
  748.  
  749. /* Report a fatal error message and terminate. */
  750. extern void flexfatal PROTO((char[]));
  751.  
  752. /* Report an error message formatted with one integer argument. */
  753. extern void lerrif PROTO((char[], int));
  754.  
  755. /* Report an error message formatted with one string argument. */
  756. extern void lerrsf PROTO((char[], char[]));
  757.  
  758. /* Spit out a "# line" statement. */
  759. extern void line_directive_out PROTO((FILE*));
  760.  
  761. /* Mark the current position in the action array as the end of the section 1
  762.  * user defs.
  763.  */
  764. extern void mark_defs1 PROTO((void));
  765.  
  766. /* Mark the current position in the action array as the end of the prolog. */
  767. extern void mark_prolog PROTO((void));
  768.  
  769. /* Generate a data statment for a two-dimensional array. */
  770. extern void mk2data PROTO((int));
  771.  
  772. extern void mkdata PROTO((int));    /* generate a data statement */
  773.  
  774. /* Return the integer represented by a string of digits. */
  775. extern int myctoi PROTO((char []));
  776.  
  777. /* Return a printable version of the given character, which might be
  778.  * 8-bit.
  779.  */
  780. extern char *readable_form PROTO((int));
  781.  
  782. /* Write out one section of the skeleton file. */
  783. extern void skelout PROTO((void));
  784.  
  785. /* Output a yy_trans_info structure. */
  786. extern void transition_struct_out PROTO((int, int));
  787.  
  788. /* Only needed when using certain broken versions of bison to build parse.c. */
  789. extern void *yy_flex_xmalloc PROTO(( int ));
  790.  
  791. /* Set a region of memory to 0. */
  792. extern void zero_out PROTO((char *, int));
  793.  
  794.  
  795. /* from file nfa.c */
  796.  
  797. /* Add an accepting state to a machine. */
  798. extern void add_accept PROTO((int, int));
  799.  
  800. /* Make a given number of copies of a singleton machine. */
  801. extern int copysingl PROTO((int, int));
  802.  
  803. /* Debugging routine to write out an nfa. */
  804. extern void dumpnfa PROTO((int));
  805.  
  806. /* Finish up the processing for a rule. */
  807. extern void finish_rule PROTO((int, int, int, int));
  808.  
  809. /* Connect two machines together. */
  810. extern int link_machines PROTO((int, int));
  811.  
  812. /* Mark each "beginning" state in a machine as being a "normal" (i.e.,
  813.  * not trailing context associated) state.
  814.  */
  815. extern void mark_beginning_as_normal PROTO((register int));
  816.  
  817. /* Make a machine that branches to two machines. */
  818. extern int mkbranch PROTO((int, int));
  819.  
  820. extern int mkclos PROTO((int));    /* convert a machine into a closure */
  821. extern int mkopt PROTO((int));    /* make a machine optional */
  822.  
  823. /* Make a machine that matches either one of two machines. */
  824. extern int mkor PROTO((int, int));
  825.  
  826. /* Convert a machine into a positive closure. */
  827. extern int mkposcl PROTO((int));
  828.  
  829. extern int mkrep PROTO((int, int, int));    /* make a replicated machine */
  830.  
  831. /* Create a state with a transition on a given symbol. */
  832. extern int mkstate PROTO((int));
  833.  
  834. extern void new_rule PROTO((void));    /* initialize for a new rule */
  835.  
  836.  
  837. /* from file parse.y */
  838.  
  839. /* Write out a message formatted with one string, pinpointing its location. */
  840. extern void format_pinpoint_message PROTO((char[], char[]));
  841.  
  842. /* Write out a message, pinpointing its location. */
  843. extern void pinpoint_message PROTO((char[]));
  844.  
  845. /* Write out a warning, pinpointing it at the given line. */
  846. void line_warning PROTO(( char[], int ));
  847.  
  848. /* Write out a message, pinpointing it at the given line. */
  849. void line_pinpoint PROTO(( char[], int ));
  850.  
  851. /* Report a formatted syntax error. */
  852. extern void format_synerr PROTO((char [], char[]));
  853. extern void synerr PROTO((char []));    /* report a syntax error */
  854. extern void warn PROTO((char []));    /* report a warning */
  855. extern int yyparse PROTO((void));    /* the YACC parser */
  856.  
  857.  
  858. /* from file scan.l */
  859.  
  860. /* The Flex-generated scanner for flex. */
  861. extern int flexscan PROTO((void));
  862.  
  863. /* Open the given file (if NULL, stdin) for scanning. */
  864. extern void set_input_file PROTO((char*));
  865.  
  866. /* Wrapup a file in the lexical analyzer. */
  867. extern int yywrap PROTO((void));
  868.  
  869.  
  870. /* from file sym.c */
  871.  
  872. /* Save the text of a character class. */
  873. extern void cclinstal PROTO ((Char [], int));
  874.  
  875. /* Lookup the number associated with character class. */
  876. extern int ccllookup PROTO((Char []));
  877.  
  878. extern void ndinstal PROTO((char[], Char[]));    /* install a name definition */
  879. /* Increase maximum number of SC's. */
  880. extern void scextend PROTO((void));
  881. extern void scinstal PROTO((char[], int));    /* make a start condition */
  882.  
  883. /* Lookup the number associated with a start condition. */
  884. extern int sclookup PROTO((char[]));
  885.  
  886.  
  887. /* from file tblcmp.c */
  888.  
  889. /* Build table entries for dfa state. */
  890. extern void bldtbl PROTO((int[], int, int, int, int));
  891.  
  892. extern void cmptmps PROTO((void));    /* compress template table entries */
  893. extern void expand_nxt_chk PROTO((void));    /* increase nxt/chk arrays */
  894. extern void inittbl PROTO((void));    /* initialize transition tables */
  895. /* Make the default, "jam" table entries. */
  896. extern void mkdeftbl PROTO((void));
  897.  
  898. /* Create table entries for a state (or state fragment) which has
  899.  * only one out-transition.
  900.  */
  901. extern void mk1tbl PROTO((int, int, int, int));
  902.  
  903. /* Place a state into full speed transition table. */
  904. extern void place_state PROTO((int*, int, int));
  905.  
  906. /* Save states with only one out-transition to be processed later. */
  907. extern void stack1 PROTO((int, int, int, int));
  908.  
  909.  
  910. /* from file yylex.c */
  911.  
  912. extern int yylex PROTO((void));
  913.